package exception;
/**
 * try catch 异常处理机制
 * */
public class TryCatchDemo {
    public static void main(String[] args) {
        try{System.out.println("程序开始");
        //String num = null;
            String num = "abcdef";
        //String内部是一个可变的char()数组 不能调用方法
        System.out.println(num.length());
            System.out.println(num.charAt(5));
            System.out.println(Integer.parseInt(num));
            //永远走不到此处
            System.out.println("shchcjskcjslj");
        }
        catch (NullPointerException|StringIndexOutOfBoundsException e){
            System.out.println("捕获了空指针或下标越界异常并处理");
        }
        catch (Exception e){
            System.out.println("出现了未知异常");
        }
        System.out.println("程序结束");

    }
}
